#include <iostream>
#include "Calculator.h"


/*
   我们知道，要想发生多态，必须有父类的指针或引用指向子类的对象
*/
void test_Add()
{
    Calculator *p = new addAlgo;
    p->num_1 = 1;
    p->num_2 = 2;

    std::cout << p->num_1 << "+" << p->num_2 << "=" << p->getResult() <<std::endl;

    delete p;
}

void test_Sub()
{
    Calculator *p = new SubAlgo;
    p->num_1 = 10;
    p->num_2 = 5;

    std::cout << p->num_1 << "-" << p->num_2 << "=" << p->getResult() <<std::endl;

    delete p;
}

void test_Mul()
{
    Calculator *p = new MulAlgo;
    p->num_1 = 10;
    p->num_2 = 5;

    std::cout << p->num_1 << "x" << p->num_2 << "=" << p->getResult() <<std::endl;

    delete p;
}


/*
    利用多态，使用闭合原则完成1个计算器类
*/
int main(int, char**) 
{
    test_Add();
    test_Sub();
    test_Mul();

    std::cout << "Hello, world!\n";
    system("pause");
    return 0;
}
